package com.intelligent.system.auth.controller;

import com.intelligent.system.auth.dto.*;
import com.intelligent.system.auth.service.IRoleService;
import com.intelligent.system.common.response.ResultDO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

@Api(tags = "角色管理")
@RestController
@RequestMapping("/api/role")
@Validated
public class RoleController {
    @Resource
    private IRoleService roleService;

    @ApiOperation("获取角色详情")
    @GetMapping("/{id}")
    public ResultDO<RoleDTO> getRoleInfo(
            @ApiParam("角色ID") @PathVariable("id") @Valid Long id) {
        return roleService.getRoleById(id);
    }

    @ApiOperation("获取角色列表")
    @PostMapping("/list")
    public ResultDO<List<RoleDTO>> getRoleList(
            @ApiParam("查询参数") @RequestBody @Valid RoleQueryDTO param) {
        return roleService.getRoleList(param);
    }

    @ApiOperation("新增角色")
    @PostMapping("/add")
    public ResultDO<?> addRole(
            @ApiParam("角色信息") @RequestBody @Valid RoleDTO param) {
        return roleService.addRole(param);
    }

    @ApiOperation("修改角色")
    @PostMapping("/update")
    public ResultDO<?> updateRole(
            @ApiParam("角色信息") @RequestBody @Valid RoleDTO param) {
        return roleService.updateRole(param);
    }

    @ApiOperation("修改角色状态")
    @PostMapping("/status")
    public ResultDO<?> updateRoleStatus(
            @ApiParam("状态修改参数") @RequestBody @Valid RoleStatusDTO param) {
        return roleService.updateRoleStatus(param.getRoleId(), param.getStatus());
    }

    @ApiOperation("删除角色")
    @GetMapping("/delete/{id}")
    public ResultDO<?> deleteRole(
            @ApiParam("角色ID") @PathVariable("id") @Valid Long id) {
        return roleService.deleteRoleById(id);
    }
} 